
import { ContainerHost } from "../../Container";
import { GroupManService } from "../GroupManService";
import { HighlightTool } from "./HighlightTool";
import { IHighlightManager } from "./IHighlightManager";

export class HighlightMan implements IHighlightManager {
    private tool!: HighlightTool;
    constructor(private viewer: Sippreep.Viewing.Viewer3D & { toolController: any }) {

    }
    load(): boolean {
        this.tool = new HighlightTool(this.viewer);
        this.viewer.toolController.registerTool(this.tool);
        this.viewer.toolController.activateTool(this.tool.getName());
        this.addFilterWhiteList();
        return true;
    }
    unload(): boolean {
        if (this.tool.isActive()) {
            this.viewer.toolController.deactivateTool(this.tool.getName());
        }
        this.viewer.toolController.deregisterTool(this.tool);
        return true;
    }
    private addFilterWhiteList(d?: { groups: { selection: { name: string, dbIds: number[] }[] }[] }) {
        if (!this.tool || !this.tool.isActive()) {
            return;
        }
        let data: { groups: any[] } = d ?? ContainerHost.Current.Get(GroupManService).getData();
        let groupData: { selection: { dbIds: number[], name: string, url: string }[] }[] = data.groups;
        for (const g of groupData) {
            for (const s of g.selection) {
                this.tool.filter.addPassList(s.name, s.dbIds);
            }
        }

    }

}
